<?php

  session_start();
  include "config.php";
  include "ALmailingList.php";

  if(isset($_SESSION["user"]))
  {
    include "$header";
    include "$body";

    if(isset($_SESSION["ml_title"]))
    {
?>

<div style="position:absolute; top:0px; left:1px; border:0;">
  <span class="prevPage">Catalogue Mailing List > </span>
  <span class="page">Confirm Details</span>
</div>
  
<?php

      include "$H_ml";

      $title = $_SESSION["ml_title"];
      $surname = $_SESSION["ml_surname"];
      $given_name = $_SESSION["ml_given_name"];
      $address = $_SESSION["ml_address"];
      $pcode = $_SESSION["ml_pcode"];

      if(isset($_GET["yes"]))
      {
        if(addToMailingList($title, $surname, $given_name, $address, $pcode) == false)
        {
          showForm();
          echo "<SCRIPT language='Javascript'>\n";
          echo "  mailingList.title.options[0] = new Option('" . $title . "', '" . $title . "');\n";
          echo "  mailingList.surname.value='" . $surname . "';\n";
          echo "  mailingList.given_name.value='" . $given_name . "';\n";
          echo "  mailingList.address.value='" . $address . "';\n";
          echo "  mailingList.pcode.value='" . $pcode . "';\n";
          echo "  alert('The details could not be added.  Please try again.');";
          echo "</SCRIPT>";
        }
        else
        {
          $_SESSION["ml_success"] = "true";
          echo "<SCRIPT language='Javascript'>";
          echo "  window.location.href = 'mailingList_2success.php';";
          echo "</SCRIPT>";
        }
      }
	  else if(isset($_GET["no"]))
      {
          echo "<SCRIPT language='Javascript'>";
          echo "  window.location.href = 'mailingList.php'";
          echo "</SCRIPT>";
      }
      else
      {
        showForm();
        echo "<SCRIPT language='Javascript'>\n";
        echo "  mailingList.title.options[0] = new Option('" . $title . "', '" . $title . "');\n";
        echo "  mailingList.surname.value='" . $surname . "';\n";
        echo "  mailingList.given_name.value='" . $given_name . "';\n";
        echo "  mailingList.address.value='" . $address . "';\n";
        echo "  mailingList.pcode.value='" . $pcode . "';\n";
        echo "</SCRIPT>";
      }
    }
	else
    {
      echo "<SCRIPT language='Javascript'>";
      echo "  window.location.href = 'mailingList.php';";
      echo "</SCRIPT>";
    }
    include "$footer";
  }
  else
  {
    session_destroy();
    echo "<SCRIPT language='Javascript'>";
    echo "  parent.window.location.href = 'index.php';";
    echo "</SCRIPT>";
  }

  function showForm()
  {

?>

<b>CONFIRMATION: ARE THESE DETAILS ACCURATE?</b>
<p>

<FORM name="mailingList" action="" method="get">
<TABLE class="mailingList" cellspacing="5" cellpadding="5">
  <TR>
    <TD class="mlField">
	  Title<font color="red">*</font>
	</TD>
    <TD class="mlDetails">
	  <select class="mailingListConfirm" name="title" style="width:70px;">
	  </select>
	</TD>
  </TR>
  <TR>
    <TD class="mlField">
	  Surname<font color="red">*</font>
	</TD>
    <TD class="mlDetails">
	  <input type="text" class="mailingListConfirm" name="surname" style="width:150px;" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="mlField">
	  Given Name<font color="red">*</font>
	</TD>
	<TD class="mlDetails">
	  <input type="text" class="mailingListConfirm" name="given_name" style="width:150px" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="mlField">
	  Address<font color="red">*</font>
	</TD>
    <TD class="mlDetails">
	  <input type="text" class="mailingListConfirm" name="address" style="width:150px" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="mlField">
	  Post Code<font color="red">*</font>
	</TD>
    <TD class="mlDetails">
	  <input type="text" class="mailingListConfirm" name="pcode" style="width:50px" readonly />
	</TD>
  </TR>
</TABLE>

<p>

<input class="submit_off" type="submit" value="No" name="no" onmouseover="className='submit_on'" onmouseout="className='submit_off'" />
&nbsp;&nbsp;
<input class="submit_off" type="submit" value="Yes" name="yes" onmouseover="className='submit_on'" onmouseout="className='submit_off'" />

</FORM>

</CENTER>

</BODY>

<?php

  }

?>